﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TinyCinema;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System.Timers;
using TinyCinema.Bussiness;


namespace TinyCinema.Bussiness.Schedule
{
    public class Schedule : DependencyObject
    {
        public static DependencyProperty lstScheduleProperty = DependencyProperty.Register("lstSchedule", typeof(ObservableCollection<Data.Schedule>), typeof(Schedule));
        public ObservableCollection<Data.Schedule> lstSchedule
        {
            get { return (ObservableCollection<Data.Schedule>)GetValue(lstScheduleProperty); }
            set { SetValue(lstScheduleProperty, value);}
        }
        public static DependencyProperty lstDealMovieProperty = DependencyProperty.Register("lstDealMovie", typeof(ObservableCollection<Data.Movie>), typeof(Schedule));
        public ObservableCollection<Data.Movie> lstDealMovie
        {
            get { return (ObservableCollection<Data.Movie>)GetValue(lstDealMovieProperty); }
            set { SetValue(lstDealMovieProperty, value); }
        }
        public ObservableCollection<Data.Room> lstRoom
        {
            get { return Data.Room.lstRoom; }
        }
        public ObservableCollection<Data.Movie> lstMovie
        {
            get { return Data.Movie.lstMovie; }
        }
        public static DependencyProperty SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(int), typeof(Schedule));
        
        public int SelectedIndex
        {
            get { return (int)GetValue(SelectedIndexProperty); }
            set
            {
                SetValue(SelectedIndexProperty, value);
            }
        }
        public static DependencyProperty Searching_MovieProperty = DependencyProperty.Register("Searching_Movie", typeof(Data.Movie), typeof(Schedule));
        public Data.Movie Searching_Movie
        {
            get { return (Data.Movie)GetValue(Searching_MovieProperty); }
            set
            {
                SetValue(Searching_MovieProperty, value);
            }
        }
        public static DependencyProperty Searching_RoomProperty = DependencyProperty.Register("Searching_Room", typeof(Data.Room), typeof(Schedule));
        public Data.Room Searching_Room
        {
            get { return (Data.Room)GetValue(Searching_RoomProperty); }
            set
            {
                SetValue(Searching_RoomProperty, value);
            }
        }
        public static DependencyProperty Searching_DayProperty = DependencyProperty.Register("Searching_Day", typeof(DateTime), typeof(Schedule));
        public DateTime Searching_Day
        {
            get { return (DateTime)GetValue(Searching_DayProperty); }
            set
            {
                SetValue(Searching_DayProperty, value);
            }
        }
        public static DependencyProperty IsSearchingProperty = DependencyProperty.Register("IsSearching", typeof(bool), typeof(Schedule));
        public bool IsSearching
        {
            get { return (bool)GetValue(IsSearchingProperty); }
            set
            {
                SetValue(IsSearchingProperty, value);
            }
        }

        public static DependencyProperty DealSelectedProperty = DependencyProperty.Register("DealSelected", typeof(Data.Movie), typeof(Schedule));
        public Data.Movie DealSelected
        {
            get { return (Data.Movie)GetValue(DealSelectedProperty); }
            set { SetValue(DealSelectedProperty, value); }
        }

        public static DependencyProperty lstScheduleTypeSelectedProperty = DependencyProperty.Register("lstScheduleTypeSelected", typeof(ObservableCollection<Data.ScheduleType>), typeof(Schedule));
        public ObservableCollection<Data.ScheduleType> lstScheduleTypeSelected
        {
            get { return (ObservableCollection<Data.ScheduleType>)GetValue(lstScheduleTypeSelectedProperty); }
            set { SetValue(lstScheduleTypeSelectedProperty, value); }
        }

        public static DependencyProperty ScheduleTypeSelectedProperty = DependencyProperty.Register("ScheduleTypeSelected", typeof(Data.ScheduleType), typeof(Schedule));
        public Data.ScheduleType ScheduleTypeSelected
        {
            get { return (Data.ScheduleType)GetValue(ScheduleTypeSelectedProperty); }
            set { SetValue(ScheduleTypeSelectedProperty, value);}
        }

        public static DependencyProperty lstScheduleSelectedProperty = DependencyProperty.Register("lstScheduleSelected", typeof(ObservableCollection<DealSchedule>), typeof(Schedule));
        public ObservableCollection<DealSchedule> lstScheduleSelected
        {
            get { return (ObservableCollection<DealSchedule>)GetValue(lstScheduleSelectedProperty); }
            set { SetValue(lstScheduleSelectedProperty, value); }
        }
        public static DependencyProperty SelectedScheduleProperty = DependencyProperty.Register("SelectedSchedule", typeof(DealSchedule), typeof(Schedule));
        public DealSchedule SelectedSchedule
        {
            get { return (DealSchedule)GetValue(SelectedScheduleProperty); }
            set { SetValue(SelectedScheduleProperty, value); }
        }
        public static DependencyProperty ScheduleOrderingProperty = DependencyProperty.Register("ScheduleOrdering", typeof(Data.Schedule), typeof(Schedule));
        public Data.Schedule ScheduleOrdering
        {
            get { return (Data.Schedule)GetValue(ScheduleOrderingProperty); }
            set { SetValue(ScheduleOrderingProperty, value); }
        }
        public static ObservableCollection<Data.DeskType> lstDeskType 
        {
            get { return Data.DeskType.lstType; }
        }
        public static DependencyProperty lstDeskSelectedProperty = DependencyProperty.Register("lstDeskSelected", typeof(ObservableCollection<Data.Desk>), typeof(Schedule));
        public ObservableCollection<Data.Desk> lstDeskSelected
        {
            get { return (ObservableCollection<Data.Desk>)GetValue(lstDeskSelectedProperty); }
            set { SetValue(lstDeskSelectedProperty, value); }
        }
        public static DependencyProperty CustomerIDOrderingProperty = DependencyProperty.Register("CustomerIDOrdering", typeof(string), typeof(Schedule));
        public string CustomerIDOrdering
        {
            get { return (string)GetValue(CustomerIDOrderingProperty); }
            set {
                SetValue(CustomerIDOrderingProperty, value);
            }
        }
        public static DependencyProperty BookedTicketIDProperty = DependencyProperty.Register("BookedTicketID", typeof(string), typeof(Schedule));
        public string BookedTicketID
        {
            get { return (string)GetValue(BookedTicketIDProperty); }
            set
            {
                SetValue(BookedTicketIDProperty, value);
            }
        }
        public static DependencyProperty TotalValueProperty = DependencyProperty.Register("TotalValue", typeof(decimal), typeof(Schedule));
        public decimal TotalValue
        {
            get { return (decimal)GetValue(TotalValueProperty); }
            set
            {
                SetValue(TotalValueProperty, value);
            }
        }
        public ICommand CreateCommand { get; set; }
        public ICommand DeleteCommand { get; set; }
        public ICommand SaveCommand { get; set; }
        public ICommand StartSearchCommand { get; set; }
        public ICommand SearchCommand { get; set; }
        public ICommand CancelSearchCommand { get; set; }
        public ICommand SelectDeskCommand { get; set; }
        public ICommand CheckOutCommand { get; set; }
        public ICommand PayCommand { get; set; }
        public ICommand BookCommand { get; set; }
        public ICommand PayCancelCommand { get; set; }
        public ICommand Searching_ClearMovieCommand { get; set; }
        public ICommand Searching_ClearRoomCommand { get; set; }
        public ICommand Searching_ClearDayCommand { get; set; }
        public ICommand CheckCustomerIDCommand { get; set; }
        public ICommand PrintCommand { get; set; }

        public Messenger Messenger { get; set; }
        Timer RefreshTimer = new Timer(1000);
        int DeskOrderingCount=0;
        public Schedule()
        {
            
            lstDeskSelected = new ObservableCollection<Data.Desk>();
            lstScheduleTypeSelected = new ObservableCollection<Data.ScheduleType>();
            lstScheduleSelected = new ObservableCollection<DealSchedule>();
            lstSchedule = Data.Schedule.GetAllSchedule();
            if (lstSchedule.Count > 0)
                ScheduleOrdering = lstSchedule[0];
            Messenger = new Bussiness.Messenger();            
            RefreshTimer.Elapsed += RefreshTimer_Elapsed;
            lstDealMovie = new ObservableCollection<Data.Movie>();
            #region Command
            CreateCommand = new RelayCommand<object>(
                (s) => true,
                (s) =>
                {
                    if (lstMovie.Count == 0)
                        Messenger.Send(new Message.ListMovieNotFound());
                    else if (lstRoom.Count == 0)
                        Messenger.Send(new Message.ListRoomNotFound());
                    else if (Data.ScheduleType.lstType.Count==0)
                        Messenger.Send(new Message.ListScheduleTypeNotFound());
                    else lstSchedule.Add(new Data.Schedule());                    
                });
             DeleteCommand = new RelayCommand<object>(
                (s) => true,
                (s) =>
                {
                    var message1 = new Message.DeleteConfirmation();
                    Messenger.Send(message1);
                    if (message1.Result == MessageBoxResult.Yes)
                    {
                        try
                        {
                            lstSchedule[SelectedIndex].Delete();
                            lstSchedule.RemoveAt(SelectedIndex);
                        }
                        catch
                        {
                            var message2 = new Message.DeleteFailed();
                            Messenger.Send(message2);
                            Data.Execution.Restore();
                        }

                    }
                });
             SaveCommand = new RelayCommand<Data.Schedule>(
                 (s) => true,
                 (s) =>
                 {

                     if (s != null)
                     {
                         if (!s.Check())
                         {
                             Messenger.Send(new Message.CheckFailed());
                             return;
                         }
                         try { s.Save(); }
                         catch { Data.Execution.Restore(); }
                     }
                 });
             Searching_ClearMovieCommand = new RelayCommand<Data.Schedule>(
                 (s) => true,
                 (s) =>
                 {
                     Searching_Movie = null;
                 });
             Searching_ClearRoomCommand = new RelayCommand<Data.Schedule>(
                  (s) => true,
                  (s) =>
                  {
                      Searching_Room = null;
                  });
             Searching_ClearDayCommand = new RelayCommand<Data.Schedule>(
                   (s) => true,
                   (s) =>
                   {
                       Searching_Day = DateTime.MinValue;
                   });
             StartSearchCommand = new RelayCommand<Data.Schedule>(
                    (s) => true,
                    (s) =>
                    {
                        lstSchedule = Data.Schedule.Search(Searching_Movie, Searching_Room, Searching_Day);
                    });
             SearchCommand = new RelayCommand<Data.Schedule>(
                     (s) => true,
                     (s) =>
                     {
                         IsSearching = true;
                     });
             CancelSearchCommand = new RelayCommand<Data.Schedule>(
                      (s) => true,
                      (s) =>
                      {
                          IsSearching = false;
                          lstSchedule = Data.Schedule.GetAllSchedule();
                      });
            SelectDeskCommand = new RelayCommand<Data.Desk>(
                       (s) => true,
                       (s) =>
                       {                           
                           switch (s.Status)
                           {
                               case Data.DeskStatus.Ordered: Messenger.Send(new Message.ScheduleOrderedSelecting());
                                   return;
                               default:
                                   if (s.Status == Data.DeskStatus.Available)
                                   {
                                       s.Status = Data.DeskStatus.Ordering;
                                       ++DeskOrderingCount;
                                       lstDeskSelected.Add(s);
                                       lstDeskSelected = new ObservableCollection<Data.Desk>(lstDeskSelected.ToList());
                                   }
                                   else
                                   {
                                       s.Status = Data.DeskStatus.Available;
                                       --DeskOrderingCount;
                                       lstDeskSelected.Remove(s);
                                       lstDeskSelected = new ObservableCollection<Data.Desk>(lstDeskSelected.ToList());
                                   } 
                                   foreach (var Row in ScheduleOrdering.Room.lstDesk)
                                       if (Row[0].Range == s.Range)
                                       {
                                           int Prelocation = 0;
                                           for (int i = 0; i < Row.Count; ++i)
                                               if (Row[i].Status == Data.DeskStatus.Ordering)
                                               {
                                                   if (Prelocation != 0&&Row[i].Order - Prelocation > 1)
                                                   {
                                                       var message = new Message.ScheduleOrderingNotValid();
                                                       Messenger.Send(message);
                                                       if (s.Status == Data.DeskStatus.Available)
                                                       {
                                                           s.Status = Data.DeskStatus.Ordering;
                                                           ++DeskOrderingCount;
                                                           lstDeskSelected.Add(s);
                                                           lstDeskSelected = new ObservableCollection<Data.Desk>(lstDeskSelected.ToList());
                                                       }
                                                       else
                                                       {
                                                           s.Status = Data.DeskStatus.Available;
                                                           --DeskOrderingCount;
                                                           lstDeskSelected.Remove(s);
                                                           lstDeskSelected = new ObservableCollection<Data.Desk>(lstDeskSelected.ToList());
                                                       } 
                                                       return;
                                                   }
                                                   else Prelocation = Row[i].Order;
                                               }
                                           break;
                                       }
                                   break;
                           }
                       });
            CheckOutCommand = new RelayCommand<Data.Schedule>(
                      (s) => true,
                      (s) =>
                      {
                          if (DeskOrderingCount == 0)
                              Messenger.Send(new Message.NoDeskSelected());
                          else
                          {
                              Messenger.Send(new Message.CheckOut());
                          }
                      });
            CheckCustomerIDCommand = new RelayCommand<string>(
                      (s) => true,
                      (s) =>
                      {
                          CustomerIDOrdering = s;
                          try
                          {
                              var Customer = new Data.Customer(CustomerIDOrdering);
                              ValueCount();
                              Messenger.Send(new Message.CustmomerIDFound());                              
                          }
                          catch
                          {
                              Messenger.Send(new Message.CustmomerIDNotFound());
                          }
                      });
            PayCommand = new RelayCommand<Data.Employee>(
                      (s) => true,
                      (s) =>
                      {
                          var message = new Message.PayConfirmation();
                          Messenger.Send(message);
                          if (message.Result == MessageBoxResult.Yes)
                          {
                              Data.Customer Cus = null;
                              try
                              {
                                  Cus = new Data.Customer(CustomerIDOrdering);
                              }
                              catch { }
                              var Order = new Data.TicketOrder(Cus, s, ScheduleOrdering, lstDeskSelected);
                              Messenger.Send(new Message.PayConfirmationOK());
                          }
                      });
            BookCommand = new RelayCommand<Data.Customer>(
                      (s) => true,
                      (s) =>
                      {
                          var message = new Message.BookConfirmation();
                          Messenger.Send(message);
                          if (message.Result == MessageBoxResult.Yes)
                          {
                              BookedTicketID = (new Data.BookedTicket(s, ScheduleOrdering, lstDeskSelected)).ID;
                              var message1 = new Message.BookConfirmationOK();
                              Messenger.Send(message1);
                          }
                      });
            PayCancelCommand = new RelayCommand<string>(
                      (s) => true,
                      (s) =>
                      {
                          var message = new Message.PayCancelConfirmation();
                          Messenger.Send(message);
                          if (message.Result == MessageBoxResult.Yes)
                          {
                              lstDealMovie = new ObservableCollection<Data.Movie>();
                              lstScheduleTypeSelected = new ObservableCollection<Data.ScheduleType>();
                              lstScheduleSelected = new ObservableCollection<DealSchedule>();
                              ClearScheduleOrdering();
                              DealDeskRefresh();
                              var message1 = new Message.PayCancelConfirmationOK();
                              Messenger.Send(message1);
                          }
                      });
            PrintCommand = new RelayCommand<object>(
                      (s) => true,
                      (s) =>
                      {
                          lstDealMovie = new ObservableCollection<Data.Movie>();
                          lstScheduleTypeSelected = new ObservableCollection<Data.ScheduleType>();
                          lstScheduleSelected = new ObservableCollection<DealSchedule>();
                          ClearScheduleOrdering();
                          var message1 = new Message.PayCancelConfirmationOK();
                          Messenger.Send(message1);
                      });

            #endregion                      
        }
        public void ValueCount()
        {
            TotalValue = ScheduleOrdering.TypePrice.Price*lstDeskSelected.Count;
            foreach (var Desk in lstDeskSelected)
                TotalValue+=Desk.Type.AdditionalPrice;
            var lstPromotion = Data.Promotion.GetAllPromotion();
            Data.Promotion CurrentPromotion=null;
            Data.Customer Cus=null;
            try{
                Cus = new Data.Customer(CustomerIDOrdering);
            }
            catch{}
            foreach (var promotion in lstPromotion)
            {
                if (promotion.StartDate <= DateTime.Now && promotion.EndDate >= DateTime.Now)
                {
                    CurrentPromotion = promotion;
                    break;
                }
            }
            if (Cus == null) Cus = new Data.Customer("KH000000");
            TotalValue = decimal.Parse((double.Parse(TotalValue.ToString()) * Cus.Type.Discount).ToString());
            if (CurrentPromotion!=null)
                foreach(var CusType in CurrentPromotion.CustomerTypes)
                    if (CusType.ID == Cus.Type.ID)
                        TotalValue = decimal.Parse((double.Parse(TotalValue.ToString()) * CusType.PromotionDiscount).ToString());
        }
        public void StartRefresh()
        {
            RefreshTimer.Enabled = true;
            RefreshTimer.Start();
        }
        public void StopRefresh()
        {
            RefreshTimer.Enabled = false;
        }
        void RefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                #region Xử lý list phim để chọn
                var lstMovie = new ObservableCollection<Data.Movie>();
                foreach (var Schedule in lstSchedule)
                    if (CheckScheduleAvailable(Schedule))
                    {
                        bool Check = true;
                        foreach (var Movie in lstMovie)
                            if (Movie.ID == Schedule.Movie.ID)
                            {
                                Check = false;
                                break;
                            }
                        if (Check)
                            lstMovie.Add(new Data.Movie(Schedule.Movie.ID));
                    }

                //Nếu không có trong list mới thì remove Deal ra
                for (int i = 0; i < lstDealMovie.Count; ++i)
                {
                    bool Check = true;
                    foreach (var Movie in lstMovie)
                        if (lstDealMovie[i].ID == Movie.ID)
                        {
                            Check = false;
                            break;
                        }
                    if (Check) lstDealMovie.RemoveAt(i--);
                }
                //Nếu chưa có trong list thì add vào
                foreach (var Movie in lstMovie)
                {
                    bool Check = true;
                    foreach (var Deal in lstDealMovie)
                        if (Deal.ID == Movie.ID)
                        {
                            Check = false;
                            break;
                        }
                    if (Check) lstDealMovie.Add(Movie);
                }
                #endregion

                #region xử lý loại phim đang được chọn
                if (DealSelected != null)
                {
                    var lstScheduleType = new ObservableCollection<Data.ScheduleType>();
                    foreach (var Schedule in lstSchedule)
                        if (Bussiness.Schedule.Schedule.CheckScheduleAvailable(Schedule) && Schedule.Movie.ID == DealSelected.ID)
                        {
                            bool Check = true;
                            foreach (var ScheduleType in lstScheduleType)
                                if (ScheduleType.ID == Schedule.TypePrice.ScheduleType.ID)
                                {
                                    Check = false;
                                    break;
                                }
                            if (Check) lstScheduleType.Add(Schedule.TypePrice.ScheduleType);
                        }

                    //Nếu không có trong list mới thì remove loại ra
                    for (int i = 0; i < lstScheduleTypeSelected.Count; ++i)
                    {
                        bool Check = true;
                        foreach (var ScheduleType in lstScheduleType)
                            if (lstScheduleTypeSelected[i].ID == ScheduleType.ID)
                            {
                                Check = false;
                                break;
                            }
                        if (Check) lstScheduleTypeSelected.RemoveAt(i--);
                    }

                    //Nếu chưa có trong list thì add vào
                    foreach (var ScheduleType in lstScheduleType)
                    {
                        bool Check = true;
                        foreach (var DealScheduleType in lstScheduleTypeSelected)
                            if (ScheduleType.ID == DealScheduleType.ID)
                            {
                                Check = false;
                                break;
                            }
                        if (Check) lstScheduleTypeSelected.Add(ScheduleType);
                    }
                }
                #endregion

                #region Xử lý các xuất chiếu có sẵn
                if (DealSelected != null&&ScheduleTypeSelected!=null)
                {
                    var lstDealSchedule = new ObservableCollection<DealSchedule>();
                    foreach (var Schedule in lstSchedule)
                    {
                        if (CheckScheduleAvailable(Schedule) && Schedule.Movie.ID == DealSelected.ID && ScheduleTypeSelected.ID == Schedule.TypePrice.ScheduleType.ID)
                        {
                            var Check = true;
                            foreach (var DealSchedule in lstDealSchedule)
                                if (Schedule.Day == DealSchedule.Day)
                                {
                                    DealSchedule.lstSchedule.Add(Schedule);
                                    Check = false;
                                    break;
                                }
                            if (Check)
                            {
                                lstDealSchedule.Add(new DealSchedule());
                                lstDealSchedule[lstDealSchedule.Count - 1].Day = Schedule.Day;
                                lstDealSchedule[lstDealSchedule.Count - 1].lstSchedule.Add(Schedule);
                            }
                        }
                    }
                    //Nếu xuất chiếu bị mất thì xóa đi
                    for (int i = 0; i < lstScheduleSelected.Count; ++i)
                    {
                        var Check1 = true;
                        foreach (var DealSchedule in lstDealSchedule)
                            if (DealSchedule.Day == lstScheduleSelected[i].Day)
                            {
                                for (int j = 0; j < lstScheduleSelected[i].lstSchedule.Count; ++j)
                                {
                                    var Check2 = true;
                                    foreach (var Deal in DealSchedule.lstSchedule)
                                        if (lstScheduleSelected[i].lstSchedule[j].ID == Deal.ID)
                                        {
                                            Check2 = false;
                                            break;
                                        }
                                    if (Check2) lstScheduleSelected[i].lstSchedule.RemoveAt(j--);
                                }
                                Check1 = false;
                                break;
                            }
                        if (Check1) lstScheduleSelected.RemoveAt(i--);
                    }


                    //Nếu chưa có trong suất chiếu đang hiển thị thì thêm vào
                    foreach (var DealSchedule in lstDealSchedule)
                    {
                        var Check1 = true;
                        foreach (var ScheduleSelected in lstScheduleSelected)
                            if (DealSchedule.Day == ScheduleSelected.Day)
                            {
                                foreach (var Deal in DealSchedule.lstSchedule)
                                {
                                    var Check2 = true;
                                    foreach (var Selected in ScheduleSelected.lstSchedule)
                                        if (Deal.ID == Selected.ID)
                                            Check2 = false;
                                    if (Check2) ScheduleSelected.lstSchedule.Add(Deal);
                                }
                                Check1 = false;
                                break;
                            }
                        if (Check1) lstScheduleSelected.Add(DealSchedule);
                    }          
                }      
                #endregion
            }));
        }
        public static bool CheckScheduleAvailable(Data.Schedule Schedule)
        {
            return Schedule.Day > DateTime.Today || (Schedule.Day == DateTime.Today && (Schedule.Time > DateTime.Now.TimeOfDay));
        }
        public void ClearScheduleOrdering()
        {
            ScheduleOrdering = null;
        }
        public void DealDeskRefresh()
        {
            try
            {
                ScheduleOrdering.RefreshDeskStatus();
                lstDeskSelected = new ObservableCollection<Data.Desk>();
                CustomerIDOrdering = "";
            }
            catch { }
        }
        public void SetDealSelected(object s)
        {
            DealSelected = s as Data.Movie;
        }
        public static TicketReport LoadTicketReport()
        {
            string sql = "select VE.MaVe, TenPhim, CONCAT(Hang,ThuTu) as TenGhe, TenPC, GioChieu, NgayChieu, Gia, TenLG, TenNV, TenKH, HOADONVE.MaHDV, NgayHDV  from PHIM, GHE, PHONGCHIEU, SUATCHIEU, VE, LOAIGHE, HOADONVE, NHANVIEN, KHACHHANG where PHIM.MaPhim=SUATCHIEU.MaPhim and GHE.MaGhe=Ve.MaGhe and GHE.MaLG=LOAIGHE.MaLG and PHONGCHIEU.MaPC=SUATCHIEU.MaPC and VE.MaHDV=HOADONVE.MaHDV and VE.MaSC=SUATCHIEU.MaSC and HOADONVE.MaNV=NHANVIEN.MaNV and HOADONVE.MaKH=KHACHHANG.MaKH and HOADONVE.MaHDV=(select max(MaHDV) from HOADONVE)";
            TicketReport report = new TicketReport();
            report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
            sql = "select TenLSC from LOAISUATCHIEU where MaLSC = (select MaLSC from DONGIASUATCHIEU where MaDG = (select MaDG from SUATCHIEU where masc = (select masc from ve where mave = (select Max(mave) from ve))))";
            report.SetParameterValue("LoaiPhim", TinyCinema.Data.Execution.Excute(sql).Rows[0][0].ToString());
            return report;
        }
    }
    public class DealSchedule
    {
        public DateTime Day { get; set; }
        public ObservableCollection<Data.Schedule> lstSchedule { get; set; }
        public DealSchedule()
        {
            lstSchedule = new ObservableCollection<Data.Schedule>();
        }       
        
    }
}
